package cn.com.cifi.mars.service.impl;

import cn.com.cifi.mars.common.exception.MsgException;
import cn.com.cifi.mars.constant.CodeEnum;
import cn.com.cifi.mars.entity.UserJobOrgRelation;
import cn.com.cifi.mars.mapper.mars.UserJobOrgRelationMapper;
import cn.com.cifi.mars.service.UserJobOrgRelationService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserJobOrgRelationServiceImpl extends ServiceImpl<UserJobOrgRelationMapper, UserJobOrgRelation> implements UserJobOrgRelationService {

    @Autowired
    UserJobOrgRelationMapper userJobOrgRelationMapper;
    @Override
    public boolean syncUserJobOrgRelation(JSONObject UserJobOrgRelation) {
        try {
            UserJobOrgRelation userJobOrgRelation = new UserJobOrgRelation();
            JSONArray requestInfo = UserJobOrgRelation.getJSONArray("requestInfo");
            asd(userJobOrgRelation, requestInfo);
        }catch (Exception e){
            throw new MsgException(CodeEnum.REQUEST_PARAM_NOT_FULL_ERROR);
        }
        return true;
    }

    @Transactional
    void asd(UserJobOrgRelation userJobOrgRelation, JSONArray requestInfo) {
        for (int i = 0; i < requestInfo.size(); i ++){
            JSONObject requstInfoItem = requestInfo.getJSONObject(i);
            userJobOrgRelation.setPernr((String) requstInfoItem.get("PERNR"));
            userJobOrgRelation.setEname((String) requstInfoItem.get("ENAME"));
            userJobOrgRelation.setZjzd((String) requstInfoItem.get("ZJZD"));
            userJobOrgRelation.setZxl((String) requstInfoItem.get("ZXL"));
            userJobOrgRelation.setZxl_t((String) requstInfoItem.get("ZXL_T"));
            userJobOrgRelation.setZjs((String) requstInfoItem.get("ZJS"));
            userJobOrgRelation.setZjs_t((String) requstInfoItem.get("ZJS_T"));
            userJobOrgRelation.setZ9121cj((String) requstInfoItem.get("Z9121CJ"));
            userJobOrgRelation.setZ9121bm((String) requstInfoItem.get("Z9121BM"));
            userJobOrgRelation.setZ9121bm_t((String) requstInfoItem.get("Z9121BM_T"));
            userJobOrgRelation.setZ9121lx((String) requstInfoItem.get("Z9121LX"));
            userJobOrgRelation.setZ9121lx_t((String) requstInfoItem.get("Z9121LX_T"));
            userJobOrgRelation.setZ9121zn((String) requstInfoItem.get("Z9121ZN"));
            userJobOrgRelation.setZ9121zn_t((String) requstInfoItem.get("Z9121ZN_T"));
            userJobOrgRelation.setIsEffect((String) requstInfoItem.get("ISEFFECT"));
            userJobOrgRelation.setSource((String) requstInfoItem.get("SOURCE"));
            userJobOrgRelationMapper.insert(userJobOrgRelation);
        }
    }
}
